<template>
  <div class="wrap">
    <div class="header">
      <p>Chat</p>
      <img src="@/assets/image/close.png" alt="" @click="back" />
    </div>
    <div class="message">
      <div class="item" v-for="(item, index) in messages" :key="index">
        <p>{{ item }}</p>
        <img src="" class="avatar" alt="" />
      </div>
    </div>
    <div class="input-button">
      <input type="text" v-model="message" />
      <img src="@/assets/image/send.png" alt="" @click="sendMessage" />
    </div>
  </div>
</template>
<script setup>
  import { ref } from 'vue';
  import { useRouter } from 'vue-router';
  const router = useRouter();
  const messages = ref([]);
  const message = ref('');
  const sendMessage = () => {
    if (message.value) {
      messages.value.push(message.value);
      message.value = '';
    }
  };
  const back = () => {
    router.back();
  };
</script>
<style lang="scss" scoped>
  .wrap {
    background: #1c1e22;
    height: 100vh;
    overflow-y: scroll;
    .header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 15px;
      background: #171719;
      height: 4rem;
      p {
        color: #fff;
        font-weight: 600;
      }
      img {
        display: block;
        width: 30px;
        height: 30px;
      }
    }
    .message {
      height: calc(100vh - 8rem);
      overflow-y: scroll;
      .item {
        display: flex;
        width: 100%;
        justify-content: flex-end;
        margin-top: 2rem;
        p {
          color: rgba(153, 164, 176, 0.6);
          padding: 6px 15px;
          background: #24262b;
          margin-right: 15px;
          border-radius: 0.25rem;
        }
        img {
          display: block;
          width: 30px;
          height: 30px;
          border-radius: 50%;
          background: #3bc117;
        }
      }
    }
    .input-button {
      height: 4rem;
      display: flex;
      align-items: center;
      justify-content: center;
      input {
        display: block;
        background: #1c1e22;
        border: 1px solid #3bc117;
        border-radius: 0.25rem;
        outline: none;
        color: #fff;
        height: 2rem;
        width: 80%;
      }
      img {
        display: block;
        width: 20px;
        height: 20px;
        margin-left: 1rem;
      }
    }
  }
</style>
